#include<iostream>
#include<memory>
using namespace std;

template <class T>
ostream& operator<< (ostream& strm,const auto_ptr<T>& p)
{
	//does p own object ?

	if(p.get() == NULL)
	{
		strm<<"NULL";
	}
	else
	{
		strm<<*p;
	}
	return strm;
}

int main()
{
	auto_ptr<int> p(new int(20));
	auto_ptr<int> q;
	
	cout<<"after initialization:"<<endl;
	cout<<"p:"<<p<<endl;
	cout<<"q:"<<q<<endl;
	
	q = p;
	cout<<"after assigning auto pointers"<<endl;
	cout<<"p:"<<p<<endl;
	cout<<"q:"<<q<<endl;
	
	*q += 13;
	p = q;
	cout<<"after change and reassignment"<<endl;
	cout<<"p:"<<p<<endl;
	cout<<"q:"<<q<<endl;

	return 0;
}
